﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.DeviceManage.Project;
using ProduceBasicData.Api.DTO.DeviceDto.ProjectDto;
using ProduceBasicData.ErrorCode;

namespace ProduceBasicData.Api.Controllers.DeviceManage.Project
{
    /// <summary>
    /// 项目控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProjectController : ControllerBase
    {
        private readonly IMediator _mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public ProjectController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 创建项目维护
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateProjectMaintenance(CreateProjectMaintenanceCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 获取项目维护列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<ProjectMaintenanceDto>> GetProjectMaintenanceList([FromQuery] GetProjectMaintenanceCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 更新项目维护
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateProjectMaintenance(UpdateProjectMaintenanceCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 删除项目维护
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteProjectMaintenance(DeleteProjectMaintenanceCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 项目维护批量删除接口
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteRangeProjectMaintenance(DeleteRangeProjectMaintenanceCommand command)
        {
            return await _mediator.Send(command);
        }


        /// <summary>
        /// 创建项目表单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateProjectForm(CreateProjectFormCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 获取项目表单列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<ProjectFormDto>> GetProjectFormList([FromQuery] GetProjectFormCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 更新项目表单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateProjectForm(UpdateProjectFormCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 删除项目表单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteProjectForm(DeleteProjectFormCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 项目表单批量删除接口
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteRangeProjectForm(DeleteRangeProjectFormCommand command)
        {
            return await _mediator.Send(command);
        }



        /// <summary>
        /// 获取项目维护列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<ProjectMaintenanceDto>>> GetProjectFormRelation([FromQuery]GetProjectFormRelationCommand command)
        {
            // 通过MediatR模式将命令发送给新实现的GetProjectMaintenanceByFormIdHandler处理器
            return await _mediator.Send(command);
        }
    }
}
